package com.ysyc.driver_ee.fragment;

import android.app.Dialog;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ysyc.driver_ee.R;
import com.ysyc.driver_ee.adapter.DriverStatisticsAdapter;
import com.ysyc.driver_ee.api.HttpResource;
import com.ysyc.driver_ee.api.NetworkCallback;
import com.ysyc.driver_ee.api.RetrofitClient;
import com.ysyc.driver_ee.base.BaseFragment;
import com.ysyc.driver_ee.factory.RecyclerViewFactory;
import com.ysyc.driver_ee.model.DriverStatistical;
import com.ysyc.driver_ee.tools.ToastUtils;

import java.util.List;

import butterknife.BindView;
import io.reactivex.Observable;

/**
 * <p>描述：(这里用一句话描述这个类的作用)</p>
 * 作者： Chan<br>
 * 日期： 2018/11/8 8:53<br>
 * 版本： v1.0<br>
 */
public class DriverStatisticsFragment extends BaseFragment {


    @BindView(R.id.rv_driver_statistics_view)
    RecyclerView rvDriverStatisticsView;
    private DriverStatisticsAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_driver_statistics;
    }

    @Override
    protected void onFragmentCreate(View view) {
        super.onFragmentCreate(view);
        RecyclerViewFactory.initVerticalRvDecoration(getContext(),rvDriverStatisticsView,25);
        adapter = new DriverStatisticsAdapter(getActivity(), R.layout.rv_driver_statistics_item);
        rvDriverStatisticsView.setAdapter(adapter);
        initNetworkCallback();
    }

    private void initNetworkCallback() {
        NetworkCallback<List<DriverStatistical>> driverStatisticalVoNetworkCallback = new NetworkCallback<>(new HttpResource<List<DriverStatistical>>() {
            @Override
            public void onSuccess(List<DriverStatistical> driverStatisticalVo) {
                adapter.bindingList(driverStatisticalVo);
            }

            @Override
            public void onFailure(String errorDes) {
                ToastUtils.show(errorDes);
            }

            @Override
            public void onLoading(Dialog dialog) {

            }
        });
        Observable<List<DriverStatistical>> driverStatisticalVoObservable = RetrofitClient.getInstance().getHttpServices().driverStatisticalVo();
        driverStatisticalVoNetworkCallback.postRequest(driverStatisticalVoObservable,null);
    }

}
